package lab02.test28;

import java.util.Scanner;

/**
 * Created by dell on 2017/11/11.
 */
public class Test {
    //编写一个应用程序，要求从键盘输入一个double类型的圆的半径，计算并输出其面积。
    // 测试当输入的数据不是double型数据（如字符串“abc”）会产生什么结果，怎样处理。
    public static void main(String[] args) {
        double r;
        Scanner s = new Scanner(System.in);

            try{
                r = Double.parseDouble(s.next());//字符串
                if(r<0)
                    throw new NegativeException();//负数异常
                else if(r<1.0||r>100.0)
                    throw new NumberRangeException();//越界异常
                else{
                    System.out.println("面积是"+r*r*3.14);

                }
            }catch(NumberFormatException e){
                System.out.println("非数值异常");
            }catch(NegativeException e){
                System.out.println("负数异常");
            }catch(NumberRangeException e){
                System.out.println("越界异常");
            }
        }
    }
class NegativeException extends Exception{
    public NegativeException(){
        super();
    }
    public NegativeException(String msg){
        super(msg);
    }
    public NegativeException(String msg, Throwable cause){
        super(msg,cause);
    }
    public NegativeException(Throwable cause){
        super(cause);
    }
}
class NumberRangeException extends Exception{
    public NumberRangeException(){
        super();
    }
    public NumberRangeException(String msg){
        super(msg);
    }
    public NumberRangeException(String msg, Throwable cause){
        super(msg,cause);
    }
    public NumberRangeException(Throwable cause){
        super(cause);
    }
}

